package com.zjitc.book.controller;

import com.zjitc.book.entity.Book;
import com.zjitc.book.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@CrossOrigin
@RequestMapping("/api")
public class BookController {
    @Autowired
    private BookService bookService;

    @PreAuthorize("hasAuthority('sys:user')")
    @GetMapping("/books")
    public List<Book> getBooks(){
        return bookService.getBooks();
    }

    @GetMapping("/books/{id}")
    public Book getBookById(@PathVariable Long id){
        return bookService.getBookById(id);
    }

}